<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <script type="text/babel">
    //柯里化
    const sum = (a,b,c) => a + b + c;
    const sum1 = a => {
        return b => {
            return c => a + b + c;
        }
    }
    class Login extends React.Component {
        state = {
            username: '',
            password: '',
        }
        handleSubmit = e => {
            e.preventDefault(); // 阻止默认行为
            alert(`用户名：${this.state.username}密码：${this.state.password}`)
        }
        // 高阶函数-柯里化
        saveFormData = type => {
            return e => {
                this.setState({
                    [type]: e.target.value,
                })
            }
        }
    
        render() {
            return (
                <form onSubmit={this.handleSubmit}>
                    用户名：<input onChange={this.saveFormData('username')} type="text" name="username" />
                    密码：<input onChange={this.saveFormData('password')} type="password" name="password" />
                    <button>login</button>
                </form>
            )
        }
    }
    
    // 渲染dom
    ReactDOM.render(<Login />, document.getElementById('app'))
    </script>

</body>
</html>